package cn.egame.extraction.multithread.pojo;

import java.io.Serializable;

import cn.egame.extraction.multithread.util.EnumType_EFS.EfsInfoFromType;
import cn.egame.interfaces.fl.FileInfo;

public class EfsInfo implements Serializable, Comparable<EfsInfo>{

	private static final long serialVersionUID = -3581050526793561659L;
	
	private long efs_id;
	private String efs_type;
	private String file_name = "";
	private EfsInfoFromType type=EfsInfoFromType.fromFile;
	
	public EfsInfo(){
		
	}
	
	public EfsInfo(long efs_id){
		this.efs_id = efs_id;
	}
	
	public EfsInfo(FileInfo fileInfo){
		this.efs_id = fileInfo.getEFSId();
		this.efs_type = fileInfo.getFileUsedType().value()+"";
		this.file_name = fileInfo.getFileName();
	}
	
	public EfsInfo(long efs_id, String efs_type, String file_name, EfsInfoFromType type){
		this.efs_id = efs_id;
		this.efs_type = efs_type;
		this.file_name = file_name;
		this.type = type;
	}
	
	public long getEfs_id() {
		return efs_id;
	}
	public void setEfs_id(long efs_id) {
		this.efs_id = efs_id;
	}
	public String getFile_name() {
		return file_name;
	}
	public void setFile_name(String file_name) {
		this.file_name = file_name;
	}
	 
	
	

	public String getEfs_type() {
		return efs_type;
	}

	public void setEfs_type(String efs_type) {
		this.efs_type = efs_type;
	}

	public EfsInfoFromType getType() {
		return type;
	}

	public void setType(EfsInfoFromType type) {
		this.type = type;
	}

	@Override
	public String toString() {
		return "EfsInfo [efs_id=" + efs_id + ", efs_type=" + efs_type
				+ ", file_name=" + file_name + "]";
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj==null)
			return false;
		if(obj == this)
			return true;
		if(obj.getClass() != getClass())
			return false;
		EfsInfo efsInfo = (EfsInfo)obj;
		return efsInfo.getEfs_id() == getEfs_id() &&
				efsInfo.getFile_name().equals(getFile_name());
	}
	
	@Override
	public int hashCode() {
		if(file_name!=null){
			return (efs_id+file_name).hashCode();
		}else{
			return new Long(efs_id).hashCode();
		}
	}

	@Override
	public int compareTo(EfsInfo o) {
		if (o instanceof EfsInfo) {  
            long cmp = o.getEfs_id() - getEfs_id();  
            if (cmp != 0) {// number是第一要比较的，相当于先比较value。如果相同再比较键  
                return -(int) cmp;  
            }else {
            	if(getFile_name()!=null && o.getFile_name()!=null){
            		return getFile_name().compareTo(o.getFile_name());
            	}
            }
        } 
		return Integer.MAX_VALUE;
	}

}
